package com.bootdo.loa.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.loa.domain.TbCommentDO;
import com.bootdo.loa.service.TbCommentService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author lzy
 * @email 1992lcg@163.com
 * @date 2018-10-29 16:54:59
 */
 
@Controller
@RequestMapping("/loa/tbComment")
public class TbCommentController {
	@Autowired
	private TbCommentService tbCommentService;
	
	@GetMapping()
	String TbComment(){
	    return "loa/tbComment/tbComment";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<TbCommentDO> tbCommentList = tbCommentService.list(query);
		int total = tbCommentService.count(query);
		PageUtils pageUtils = new PageUtils(tbCommentList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "loa/tbComment/add";
	}

	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Integer id,Model model){
		TbCommentDO tbComment = tbCommentService.get(id);
		model.addAttribute("tbComment", tbComment);
	    return "loa/tbComment/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(TbCommentDO tbComment){
		tbComment.setAddTime(new Date());
		if(tbCommentService.save(tbComment)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( TbCommentDO tbComment){
		tbCommentService.update(tbComment);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer id){
		if(tbCommentService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] ids){
		tbCommentService.batchRemove(ids);
		return R.ok();
	}
	
}
